package com.crop.back.common.config;


import com.crop.back.common.utils.RedisUtil;
import com.crop.back.interceptor.LoginInterceptor;
import com.crop.back.interceptor.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * author Luge
 * description: $
 * param: $
 * return: $
 * date: $ $
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private RedisUtil redisUtil;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录拦截器
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/user/namePwdLogin",
                        "/user/emailLogin",
                        "/user/sendEmailCode",
                        "/user/emailRegister",
                        "/user/logout",
                        "/role/list",
                        "/back/feedback/list",
                        "/back/feedback/add",
                        "/back/qrcode/verify",
                        "/back/qrcode/generate",
                        "/back/qrcode/detail"
                        )
                .order(2);

        // token刷新的拦截器
        registry.addInterceptor(new RefreshTokenInterceptor(redisUtil))
                .order(1);
    }
}
